<template>
  <div class="main">
    <el-card class="card">
      <div class="button">
        <router-link to="/login">
          <el-button circle title="密码登录">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-yonghudenglu"></use>
            </svg>
          </el-button>
        </router-link>
        <el-divider direction="vertical"></el-divider>
        <router-link to="/getshare">
          <el-button circle title="获取分享文件">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-fenxiang7"></use>
            </svg>
          </el-button>
        </router-link>
      </div>
      <br>
      <h3>手机快速登录</h3>
      <br>
      <el-form :model="ruleForm"
               @submit.native.prevent ref="ruleForm"
               label-width="100px" class="demo-ruleForm">
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="ruleForm.phone" placeholder="账号密码将预设为此"></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="code">
          <el-input v-model="ruleForm.code">
            <el-button slot="append" icon="el-icon-s-promotion" @click="sendCode"/>
          </el-input>
        </el-form-item>
        <br><br>
        <el-form-item>
          <el-button type="primary" @click="submitForm" native-type="submit">登录</el-button>
        </el-form-item>

      </el-form>

    </el-card>
    <div class="foot_text">
      <el-col>Copyright ©2022 By Mr.文</el-col>
      <br>
      <el-col>桂ICP备2021009133号</el-col>
    </div>
  </div>
</template>

<script>
import Global from '../../js/global'


export default {
  name: "Login",
  data() {
    return {
      ruleForm: {
        phone: '',
        code: '',
      },
    };
  },

  methods: {
    sendCode() {
      const that = this;
      this.axios({
        url: Global.SERVER_ADDRESS + '/sms/send-code',
        params: {
          phone: that.ruleForm.phone,
          code: that.ruleForm.code,
        },
        method: 'POST',
      }).then(function (rs) {
        that.successMsg(rs.message);
      })
    },
    submitForm() {
      const that = this;
      this.axios({
        url: Global.SERVER_ADDRESS + '/users/login/phone',
        data: that.ruleForm,
        method: 'POST',
        withCredentials: true,
      }).then(function (rs) {
        that.successMsg(rs.message);
        that.$cookies.set("TOKEN", rs.data, Global.COOKIES_TIME);
        that.$router.push({path: '/index'});
      })
    },
  },

}
</script>

<style scoped>

.foot_text {
  line-height: 20px;
  color: #a9a8a8;
  position: absolute;
  bottom: 2%;
  font-size: 12px;
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", serif;
}

.main {
  position: fixed;
  width: 100%;
  height: 100%;
  background: url('../../img/login_bg.png');
  display: flex;
  justify-content: center;
  align-items: center;

}


.card {
  background-color: #FCFDFD;
  text-align: center;
  position: absolute;
  top: 10%;
  width: 20%;
  height: auto;
  padding: 3% 5% 3% 2%;
}

.button {
  margin-top: -15%;
  margin-right: -15%;
  text-align: right;
}


@media only screen and (max-width: 900px) {
  .card {
    width: 80%;
    height: auto;
  }


  .button {
    margin-top: -10%;
    margin-right: -10%;
    text-align: right;
  }

  .card {
    width: 80%;
    height: auto;
  }


  .button {
    margin-top: -10%;
    margin-right: -10%;
    text-align: right;
  }

}

.pointer:hover {
  cursor: pointer;
  color: #409EFF;
}

</style>
